package 每日一题OJ;

/**
 * @author shy_black
 * @date 2019/8/19 22:55
 * @Description:
 */
public class _191_位1的个数 {
    // you need to treat n as an unsigned value
    public int hammingWeight(int n) {
        int bit = 0;
        int mask = 1;
        for(int i = 0;i < 32;i++) {
            if((mask & n) != 0)
                bit ++;
            mask <<= 1;
        }
        return bit;
    }
}